package com.chandra.pos.employee.service;

import com.chandra.pos.SearchCriteria;
import com.chandra.pos.employee.dao.ISystemUserDAO;
import com.chandra.pos.employee.dao.entity.Employee;
import com.chandra.pos.employee.dao.entity.EmployeeRole;
import com.chandra.pos.employee.exception.SystemUserNotFoundException;
import com.chandra.pos.employee.model.EmployeeSearchCriteria;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.Date;
import java.util.List;

/**
 * 
 * Customer Service
 * 
 * @author onlinetechvision.com
 * @since 25 Mar 2012
 * @version 1.0.0
 *
 */
@Transactional(readOnly = true)
@Named
public class EmployeeManager implements IEmployeeManager {

	// CustomerDAO is injected...
    @Inject
    ISystemUserDAO systemUserDAO;
	
	/**
	 * Add Customer
	 * 
	 * @param  customer customer
	 */
	@Transactional(readOnly = false)
	@Override
	public Employee addUser(Employee customer) {
        customer.setCreated(new Date());

        return systemUserDAO.addSystemUser(customer);
	}

	/**
	 * Delete Customer
	 * 
	 * @param  customer customer
	 */
	@Transactional(readOnly = false)
	@Override
	public boolean deleteUser(Employee customer) {
        systemUserDAO.deleteUser(customer);
        return true;
	}
	
	/**
	 * Update Customer
	 * 
	 * @param  customer customer
	 */
	@Transactional(readOnly = false)
	@Override
	public Employee updateUser(Employee customer) {
        customer.setModified(new Date());
        return systemUserDAO.updateUser(customer);
	}
	
	/**
	 * Get Customer
	 * 
	 * @param  id Customer Id
	 */
	@Override
	public Employee getUserById(Long id) {
		return systemUserDAO.getUserById(id);
	}

	/**
	 * Get Customer List
	 * 
	 */
	@Override
	public Page getUsers(PageRequest posPagination) {
		return systemUserDAO.getUsers(posPagination);
	}

    @Override
    public Employee getUserDetail(String firstName,String lastName,String city) throws SystemUserNotFoundException{
        return systemUserDAO.getUserDetail(firstName, lastName, city);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public Employee getUserDetail(Long id) throws SystemUserNotFoundException {
        return systemUserDAO.getUserDetail(id);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public Employee getUserDetail(String userName) throws SystemUserNotFoundException {
        return systemUserDAO.getUserDetail(userName);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<Employee> searchUsers(EmployeeSearchCriteria searchCriteria) {
        return systemUserDAO.searchUsers(searchCriteria);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<Employee> searchUsers(SearchCriteria searchCriteria) {
            return systemUserDAO.searchUsers(searchCriteria);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<EmployeeRole> getUserRoles(Employee employee) {
        return systemUserDAO.getUserRoles(employee.getId());  //To change body of implemented methods use File | Settings | File Templates.
    }


}
